package com.xszx.servlet.admin.admin;

import com.xszx.bean.Manager;
import com.xszx.dao.ManagerDao;
import com.xszx.dao.impl.ManagerDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/UpdateAdminServlet")
public class UpdateAdminServlet extends HttpServlet {
    static ManagerDao managerDao = new ManagerDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        Integer id = Integer.parseInt(req.getParameter("id"));
        String managerName = req.getParameter("managername");
        String managerPassword = req.getParameter("managerpassword");
        Integer role = Integer.parseInt(req.getParameter("role"));

        managerDao.updateManager(new Manager(id, managerName, managerPassword, role));

        req.setAttribute("msg", "修改成功");
        resp.sendRedirect("GetAllAdminServlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
